package com.wsjc.web.controller.common;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.wsjc.common.core.entity.ApiCommonResultVo;
import com.wsjc.common.core.enums.MunicipalEnum;
import com.wsjc.common.core.utils.StringUtil;
import com.wsjc.manager.entity.vo.map.RegionVo;
import com.wsjc.manager.service.routine.region.WjRegionService;

@RestController
@RequestMapping(value = "/boss/common/")
public class WjCommonController {

	private Logger logger = LoggerFactory.getLogger(WjCommonController.class);
	
	@Autowired
	public WjRegionService wjRegionService ;

	/**
	 * 获取区域
	 * @param scope
	 * @return
	 */
	@RequestMapping(value = "getRegion", method = RequestMethod.GET)
	public ApiCommonResultVo getScope(String scopeId) {
		
		try {
			List<RegionVo> regionVo;
			if(StringUtil.isEmpty(scopeId) && scopeId.equals("000000")){
				regionVo = wjRegionService.queryAllProvinces();
				return new ApiCommonResultVo(0,"success",regionVo) ;
			}
			MunicipalEnum municipalEnum = MunicipalEnum.getEnum("P"+scopeId);
			if(null != municipalEnum){
	    		regionVo = wjRegionService.queryAllAreasByCityId(scopeId, null);
	    		return new ApiCommonResultVo(0,"success",regionVo) ;
	    	}
			regionVo = wjRegionService.queryAllCitysByProvinceId(scopeId);
    		return new ApiCommonResultVo(0,"success",regionVo) ;
		} catch (Exception e) {
			logger.error("boos-common|getScope find error ....", e);
			return new ApiCommonResultVo(-1, "系统异常", null) ;
		}
	}


	
	
	
	
	

}
